module.exports = function ($scope, $resource, $stateParams, $modal, toaster, sale_type) {

	//获取数据
	$scope.getDate = function(pageNo){
		$scope.searchform.loading = true;
		var para = {
			'pageNo': pageNo,
			'pageSize': $scope.itemsPerPage,
			'sale_type': sale_type,
			'sale_name': $scope.searchform.sale_name,
			'company_code': $scope.searchform.create_company
		}
		$resource('/api/as/atc/sale/getSaleList', {}, {}).save(para, function(res){
			if (res.errcode === 0) {
				$scope.productList = res.data.results;
				$scope.totalItems = res.data.totalRecord;
				$scope.searchform.loading = false;
			} else {
				toaster.error({title: '', body: '查询人员名单失败'});
			}
		});
	}

	//加载参加招徕奖励活动的机构名单
	$scope.loadCompany = function() {	
		$resource('/api/as/atc/tourist/companySimList', {}, {}).save({}, function(res){
            if (res.errcode === 0) {
				$scope.searchform.company_list = res.data;
				$scope.searchform.company_list.unshift({'company_name': '全部', 'company_code': undefined});
            } else {
                toaster.error({title: '', body: res.errmsg});
            }
        });
	}

	init();
	//初始化查询全部可参与招徕奖励的机构
	function init(){
		$scope.title = sale_type == 'J' ? '景区产品列表' : '住宿酒店列表',
		$scope.currentPage = 1;			//当前页码
		$scope.itemsPerPage = 10;		//每页显示几条
		$scope.searchform = {};
		$scope.loadCompany();
		$scope.getDate(1);
	}

	//删除产品
	$scope.delete = function(code) {
		if(confirm('删除后此产品申报的旅游团将不再获取招徕奖励！\r\n 确认删除此产品吗？')){
			$resource('/api/as/atc/sale/deleteSale', {}, {}).save({'sale_code': code}, function(res){
				if (res.errcode === 0) {
					$scope.getDate($scope.currentPage);
					toaster.success({title: '', body: '删除成功'});
				} else {
					toaster.error({title: '', body: '删除失败'});
				}
			});
		}
	}

};